package com.example.controller;

import com.example.common.Result;
import com.example.entity.College;
import com.example.entity.MbtiQuestion;
import com.example.service.MbtiQuestionService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Insert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/mbtiquestion")
public class MbtiQuestionController {
    @Resource
    private MbtiQuestionService mbtiQuestionService;
    //答题获取题目
    @GetMapping("/list")
    public Result getAllQuestions() {
        List<MbtiQuestion> questions = mbtiQuestionService.getAllQuestions();
        return Result.success(questions);
    }
    //题库管理 通过题目和维度分页查询
    @GetMapping("/selectPage")
    public Result selectPage(MbtiQuestion mbtiQuestion,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize
                             ) {
        PageInfo<MbtiQuestion> pageInfo = mbtiQuestionService.selectPage(mbtiQuestion,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    @PostMapping("/insert")
    public Result add(@RequestBody MbtiQuestion mbtiQuestion){
        mbtiQuestionService.add(mbtiQuestion);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody MbtiQuestion mbtiQuestion){
        mbtiQuestionService.update(mbtiQuestion);
        return Result.success();
    }

    @DeleteMapping("/delete/{questionId}")
    public Result delete(@PathVariable Integer questionId){
        mbtiQuestionService.delete(questionId);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        mbtiQuestionService.deleteBatch(ids);
        return Result.success();
    }
}
